package com.newlink.building.record

import android.content.Intent
import android.view.View
import com.bumptech.glide.Glide
import com.newlink.building.common_base.activities.Base_ImageZoomActivityNL
import com.newlink.building.common_base.base.NL_BaseActivity
import com.newlink.building.common_base.model.bean.OpenDoorRecordListData
import com.newlink.building.record.bean.Module_Record_OpenDoorType
import com.newlink.building.record.databinding.ActivityPreviewDetailBinding

/**
 * Created by xiaodong on 2024/11/4.
 */
class PreviewDetailActivityty : NL_BaseActivity() {
    private lateinit var mBinding: ActivityPreviewDetailBinding
    private var openDoorRecordListData: OpenDoorRecordListData? = null
    override fun attachLayoutRes(): View? {
        mBinding = ActivityPreviewDetailBinding.inflate(layoutInflater)
        return mBinding.root
    }

    override fun initData() {
        openDoorRecordListData =
            intent.getSerializableExtra("record_data") as OpenDoorRecordListData
    }

    override fun initView() {
        mBinding.titlebar.tvTitleCommon.text = getString(R.string.open_door_record)
        mBinding.titlebar.imageBack.setOnClickListener {
            onBackPressed()
        }
        mBinding.tvName.text = openDoorRecordListData?.devName
        mBinding.tvTime.text = openDoorRecordListData?.optTime?.replace("/", "-")
        openDoorRecordListData?.type?.let {
            mBinding.tvMode.text = getString(Module_Record_OpenDoorType.getResIdByCode(it))
        }

        Glide.with(this)
            .load(openDoorRecordListData?.fileUrl)
            .centerCrop()
            .placeholder(R.drawable.default_screenshot)
            .into(mBinding.ivPreview)

        mBinding.ivPreview.setOnClickListener {
            Intent(this, Base_ImageZoomActivityNL::class.java).apply {
                putExtra("image_url", openDoorRecordListData?.fileUrl)
                startActivity(this)
            }

        }

        if (openDoorRecordListData?.result == 0) {
            //失败
            mBinding.tvStatus.setTextColor(getColor(R.color.red))
            mBinding.tvStatus.text = getString(R.string.open_door_result_fail)
        } else {
            //成功
            mBinding.tvStatus.setTextColor(getColor(R.color.green))
            mBinding.tvStatus.text = getString(R.string.open_door_result_success)
        }
    }
}